<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/","images":"/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="在数据切分处理中，特别是水平切分中，中间件最终要的两个处理过程就是数据的切分、数据的聚合。选择合适的切分规则，至关重要，因为它决定了后续数据聚合的难易程度，甚至可以避免跨库的数据聚合处理。">
<meta property="og:type" content="article">
<meta property="og:title" content="Mycat 分片规则">
<meta property="og:url" content="http://littlefxc.github.io/2021/09/27/Mycat-%E5%88%86%E7%89%87%E8%A7%84%E5%88%99/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:description" content="在数据切分处理中，特别是水平切分中，中间件最终要的两个处理过程就是数据的切分、数据的聚合。选择合适的切分规则，至关重要，因为它决定了后续数据聚合的难易程度，甚至可以避免跨库的数据聚合处理。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-09-27T07:05:21.000Z">
<meta property="article:modified_time" content="2021-09-27T08:36:23.150Z">
<meta property="article:author" content="一年春又来">
<meta property="article:tag" content="mycat">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://littlefxc.github.io/2021/09/27/Mycat-%E5%88%86%E7%89%87%E8%A7%84%E5%88%99/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>Mycat 分片规则 | 一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-%E5%88%86%E7%89%87%E6%9E%9A%E4%B8%BE"><span class="nav-text">1. 分片枚举</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-%E5%9B%BA%E5%AE%9A%E5%88%86%E7%89%87-hash-%E7%AE%97%E6%B3%95"><span class="nav-text">2. 固定分片 hash 算法</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-%E8%8C%83%E5%9B%B4%E7%BA%A6%E5%AE%9A"><span class="nav-text">3. 范围约定</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-%E5%8F%96%E6%A8%A1"><span class="nav-text">4. 取模</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-%E6%8C%89%E6%97%A5%E6%9C%9F%EF%BC%88%E5%A4%A9%EF%BC%89%E5%88%86%E7%89%87"><span class="nav-text">5. 按日期（天）分片</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-%E5%8F%96%E6%A8%A1%E8%8C%83%E5%9B%B4%E7%BA%A6%E6%9D%9F"><span class="nav-text">6. 取模范围约束</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-%E6%88%AA%E5%8F%96%E6%95%B0%E5%AD%97%E5%81%9A-hash-%E6%B1%82%E6%A8%A1%E8%8C%83%E5%9B%B4%E7%BA%A6%E6%9D%9F"><span class="nav-text">7. 截取数字做 hash 求模范围约束</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#8-%E5%BA%94%E7%94%A8%E6%8C%87%E5%AE%9A"><span class="nav-text">8. 应用指定</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#9-%E6%88%AA%E5%8F%96%E6%95%B0%E5%AD%97-hash-%E8%A7%A3%E6%9E%90"><span class="nav-text">9. 截取数字 hash 解析</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#10-%E4%B8%80%E8%87%B4%E6%80%A7-hash"><span class="nav-text">10. 一致性 hash</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#11-%E6%8C%89%E5%8D%95%E6%9C%88%E5%B0%8F%E6%97%B6%E6%8B%86%E5%88%86"><span class="nav-text">11. 按单月小时拆分</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#12-%E8%8C%83%E5%9B%B4%E6%B1%82%E6%A8%A1%E5%88%86%E7%89%87"><span class="nav-text">12. 范围求模分片</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#13-%E6%97%A5%E6%9C%9F%E8%8C%83%E5%9B%B4HASH%E5%88%86%E7%89%87"><span class="nav-text">13. 日期范围HASH分片</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#14-%E5%86%B7%E7%83%AD%E6%95%B0%E6%8D%AE%E5%88%86%E7%89%87"><span class="nav-text">14. 冷热数据分片</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#15-%E8%87%AA%E7%84%B6%E6%9C%88%E5%88%86%E7%89%87"><span class="nav-text">15. 自然月分片</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">234</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">38</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">125</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/09/27/Mycat-%E5%88%86%E7%89%87%E8%A7%84%E5%88%99/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Mycat 分片规则
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2021-09-27 15:05:21 / 修改时间：16:36:23" itemprop="dateCreated datePublished" datetime="2021-09-27T15:05:21+08:00">2021-09-27</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p>在数据切分处理中，特别是水平切分中，中间件最终要的两个处理过程就是数据的切分、数据的聚合。选择合适的切分规则，至关重要，因为它决定了后续数据聚合的难易程度，甚至可以避免跨库的数据聚合处理。</p>
<span id="more"></span>

<h1 id="1-分片枚举"><a href="#1-分片枚举" class="headerlink" title="1. 分片枚举"></a>1. 分片枚举</h1><p>通过在配置文件中配置可能的枚举 id，自己配置分片。</p>
<p>该分片规则适合于特定的场景，比如有些业务需要安装省份或区县来做保存，而全国省份区县是固定的，这类业务可以采用本规则。</p>
<p>配置如下：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-intfile&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>hash-int<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;hash-int&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByFileMap&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;mapFile&quot;</span>&gt;</span>partition-hash-int.txt<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;type&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;defaultNode&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>mapFile</td>
<td>标识配置文件名称</td>
</tr>
<tr>
<td>type</td>
<td>默认值为 0，0 表示 Integer，非零表示 String</td>
</tr>
<tr>
<td>defaultNode</td>
<td>默认节点:小于 0 表示不设置默认节点，大于等于 0 设置默认节点</td>
</tr>
</tbody></table>
<p>partition-hash-int.txt 配置：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">10000&#x3D;0</span><br><span class="line">10010&#x3D;1</span><br><span class="line">DEFAULT_NODE&#x3D;1      &#x2F;&#x2F;默认节点</span><br></pre></td></tr></table></figure>

<blockquote>
<p><strong>注意</strong></p>
<p>默认节点的作用：枚举分片时，如果碰到不识别的枚举值，就让它路由到默认节点<br>如果不配置默认节点（defaultNode 值小于 0 表示不配置默认节点），碰到不识别的枚举值就会报错<br>like this：can’t find datanode for sharding column:column_name val:ffffffff</p>
</blockquote>
<h1 id="2-固定分片-hash-算法"><a href="#2-固定分片-hash-算法" class="headerlink" title="2. 固定分片 hash 算法"></a>2. 固定分片 hash 算法</h1><p>本条规则类似于十进制的求模运算，区别在于是二进制的操作,是取 id 的二进制低 10 位，即 id 二进制 &amp;1111111111。<br>此算法的优点在于如果按照 10 进制取模运算，在连续插入 1-10 时候 1-10 会被分到 1-10 个分片，增大了插入的事务控制难度，而此算法根据二进制则可能会分到连续的分片，减少插入事务事务控制难度。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;rule1&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>func1<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;func1&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByLong&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionCount&quot;</span>&gt;</span>2,1<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionLength&quot;</span>&gt;</span>256,512<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>partitionCount</td>
<td>分片个数列表</td>
</tr>
<tr>
<td>partitionLength</td>
<td>分片范围列表</td>
</tr>
</tbody></table>
<p>分区长度：<br>默认为最大 2^n=1024 ，即最大支持 1024 分区。</p>
<p>约束：<br>count，length 两个数组的长度必须是一致的；<br>1024 = sum((count[i]*length[i]))<br>count 和 length 两个向量的点积恒等于 1024。</p>
<p>如果需要平均分配设置：平均分为 4 分片，partitionCount*partitionLength=1024。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;func1&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByLong&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionCount&quot;</span>&gt;</span>4<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionLength&quot;</span>&gt;</span>256<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h1 id="3-范围约定"><a href="#3-范围约定" class="headerlink" title="3. 范围约定"></a>3. 范围约定</h1><p>此分片适用于，提前规划好分片字段某个范围属于哪个分片。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;auto-sharding-long&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>rang-long<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;rang-long&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.AutoPartitionByLong&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;mapFile&quot;</span>&gt;</span>autopartition-long.txt<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;defaultNode&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>mapFile</td>
<td>标识配置文件名称</td>
</tr>
<tr>
<td>defaultNode</td>
<td>超过范围后的默认节点</td>
</tr>
</tbody></table>
<p>所有的节点配置都是从 0 开始，及 0 代表节点 1，此配置非常简单，即预先制定可能的 id 范围到某个分片：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># range start-end ,data node index</span><br><span class="line"># K&#x3D;1000,M&#x3D;10000.</span><br><span class="line">0-500M&#x3D;0</span><br><span class="line">500M-1000M&#x3D;1</span><br><span class="line">1000M-1500M&#x3D;2</span><br><span class="line">或</span><br><span class="line"></span><br><span class="line">0-10000000&#x3D;0</span><br><span class="line">10000001-20000000&#x3D;1</span><br></pre></td></tr></table></figure>

<h1 id="4-取模"><a href="#4-取模" class="headerlink" title="4. 取模"></a>4. 取模</h1><p>此规则为对分片字段求模运算。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;mod-long&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>mod-long<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;mod-long&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByMod&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- how many data nodes --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;count&quot;</span>&gt;</span>3<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>count</td>
<td>分片数量</td>
</tr>
</tbody></table>
<p>根据 id 进行十进制求模预算，相比固定分片 hash，此种在批量插入时可能存在批量插入单事务插入多数据分片，增大事务一致性难度。</p>
<h1 id="5-按日期（天）分片"><a href="#5-按日期（天）分片" class="headerlink" title="5. 按日期（天）分片"></a>5. 按日期（天）分片</h1><p>此规则为按天分片。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-date&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>create_time<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-date<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-date&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByDate&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;dateFormat&quot;</span>&gt;</span>yyyy-MM-dd<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sBeginDate&quot;</span>&gt;</span>2014-01-01<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sEndDate&quot;</span>&gt;</span>2014-01-02<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sPartionDay&quot;</span>&gt;</span>10<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>dateForma</td>
<td>日期格式</td>
</tr>
<tr>
<td>sBeginDate</td>
<td>开始日期</td>
</tr>
<tr>
<td>sEndDate</td>
<td>结束日期</td>
</tr>
<tr>
<td>sPartionDay</td>
<td>分区天数，即默认从开始日期算起，分隔 10 天一个分区</td>
</tr>
</tbody></table>
<p>如果配置了 sEndDate 则代表数据达到了这个日期的分片后循环从开始分片插入。<br><strong>注意</strong><br>在查询时，如果需要查询时间段应该使用between…and，使用&gt;=或者&lt;=会查询所有分片。</p>
<h1 id="6-取模范围约束"><a href="#6-取模范围约束" class="headerlink" title="6. 取模范围约束"></a>6. 取模范围约束</h1><p>此种规则是取模运算与范围约束的结合，主要为了后续数据迁移做准备，即可以自主决定取模后数据的节点分布。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-pattern&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span>TopESA - Win Cpp</span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-pattern<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-pattern&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByPattern&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;patternValue&quot;</span>&gt;</span>256<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;defaultNode&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;mapFile&quot;</span>&gt;</span>partition-pattern.txt<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>partition-pattern.txt</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># id partition range start-end ,data node index</span><br><span class="line">###### first host configuration</span><br><span class="line">1-32&#x3D;0</span><br><span class="line">33-64&#x3D;1</span><br><span class="line">65-96&#x3D;2</span><br><span class="line">97-128&#x3D;3</span><br><span class="line">######## second host configuration</span><br><span class="line">129-160&#x3D;4</span><br><span class="line">161-192&#x3D;5</span><br><span class="line">193-224&#x3D;6</span><br><span class="line">225-256&#x3D;7</span><br><span class="line">0-0&#x3D;7</span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>patternValue</td>
<td>求模基数</td>
</tr>
<tr>
<td>defaoultNod</td>
<td>默认节点</td>
</tr>
<tr>
<td>mapFile</td>
<td>配置文件路径</td>
</tr>
</tbody></table>
<p>配置文件中，1-32 即代表 id%256 后分布的范围，如果在 1-32 则在分区 1，其他类推<br>如果 id 非数字，则会分配在 defaoultNode 默认节点。</p>
<h1 id="7-截取数字做-hash-求模范围约束"><a href="#7-截取数字做-hash-求模范围约束" class="headerlink" title="7. 截取数字做 hash 求模范围约束"></a>7. 截取数字做 hash 求模范围约束</h1><p>此种规则类似于取模范围约束，此规则支持数据符号字母取模。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-prefixpattern&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-prefixpattern<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-pattern&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByPrefixPattern&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;patternValue&quot;</span>&gt;</span>256<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;prefixLength&quot;</span>&gt;</span>5<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;mapFile&quot;</span>&gt;</span>partition-pattern.txt<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>patternValue</td>
<td>求模基数</td>
</tr>
<tr>
<td>prefixLength</td>
<td>ASCII 截取的位数</td>
</tr>
<tr>
<td>mapFile</td>
<td>配置文件路径</td>
</tr>
</tbody></table>
<p>partition-pattern.txt</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"># range start-end ,data node index</span><br><span class="line"># ASCII</span><br><span class="line"># 8-57&#x3D;0-9 阿拉伯数字</span><br><span class="line"># 64、65-90&#x3D;@、A-Z</span><br><span class="line"># 97-122&#x3D;a-z</span><br><span class="line">###### first host configuration</span><br><span class="line">1-4&#x3D;0</span><br><span class="line">5-8&#x3D;1</span><br><span class="line">9-12&#x3D;2</span><br><span class="line">13-16&#x3D;3</span><br><span class="line">###### second host configuration</span><br><span class="line">17-20&#x3D;4</span><br><span class="line">21-24&#x3D;5</span><br><span class="line">25-28&#x3D;6</span><br><span class="line">29-32&#x3D;7</span><br><span class="line">0-0&#x3D;7</span><br></pre></td></tr></table></figure>

<p>配置文件中，1-32 即代表 id%256 后分布的范围，如果在 1-32 则在分区 1，其他类推。<br>此种方式类似取模范围约束，只不过采取的是将列种获取前 prefixLength 位列所有 ASCII 码的和进行求模。<br><code>sum%patternValue</code> ,获取的值，在范围内的分片数</p>
<h1 id="8-应用指定"><a href="#8-应用指定" class="headerlink" title="8. 应用指定"></a>8. 应用指定</h1><p>此规则是在运行阶段有应用自主决定路由到那个分片。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-substring&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-substring<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-substring&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionDirectBySubString&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;startIndex&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span><span class="comment">&lt;!-- zero-based --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;size&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionCount&quot;</span>&gt;</span>8<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;defaultPartition&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>partitionCount</td>
<td>分区数</td>
</tr>
<tr>
<td>defaultPartition</td>
<td>默认分区</td>
</tr>
</tbody></table>
<p>此方法为直接根据字符子串（必须是数字）计算分区号（由应用传递参数，显式指定分区号）。</p>
<p>例如：id=05-100000002，在此配置中代表根据 id 中从 startIndex=0，开始，截取 siz=2 位数字即 05，05 就是获取的分区，如果没传默认分配到 defaultPartition。</p>
<h1 id="9-截取数字-hash-解析"><a href="#9-截取数字-hash-解析" class="headerlink" title="9. 截取数字 hash 解析"></a>9. 截取数字 hash 解析</h1><p>此规则是截取字符串中的 int 数值 hash 分片。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-stringhash&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-stringhash<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-stringhash&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByString&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionLength&quot;</span>&gt;</span>512<span class="tag">&lt;/<span class="name">property</span>&gt;</span><span class="comment">&lt;!-- zero-based --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;partitionCount&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;hashSlice&quot;</span>&gt;</span>0:2<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>partitionLength</td>
<td>字符串hash求模基数</td>
</tr>
<tr>
<td>partitionCount</td>
<td>分区数</td>
</tr>
<tr>
<td>hashSlice</td>
<td>预算位，即根据子字符串中 int 值 hash 运算。 0 means str.length(), -1 means str.length()-1</td>
</tr>
</tbody></table>
<p><strong>注意</strong><br>hashSlice可以理解为substring（start，end），start为0则只表示0；<br>例1：值“45abc”，hash预算位0:2 ，取其中45进行计算<br>例2：值“aaaabbb2345”，hash预算位-4:0 ，取其中2345进行计算</p>
<h1 id="10-一致性-hash"><a href="#10-一致性-hash" class="headerlink" title="10. 一致性 hash"></a>10. 一致性 hash</h1><p>一致性 hash 预算有效解决了分布式数据的扩容问题。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-murmur&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>user_id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>murmur<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;murmur&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByMurmurHash&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 默认是 0 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;seed&quot;</span>&gt;</span>0<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 要分片的数据库节点数量，必须指定，否则没法分片 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;count&quot;</span>&gt;</span>2<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 一个实际的数据库节点被映射为这么多虚拟 节点，默认是 160 倍，也就是虚拟节点数是物理节点数的 160 倍 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;virtualBucketTimes&quot;</span>&gt;</span>160<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 节点的权重，没有指定权重的节点默认是 1。以 properties 文件的格式填写，以从 0 开始到 count-1 的整数值也就是节点索引为 key，以节点权重值为值。所有权重值必须是正整数，否则以 1 代替 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;weightMapFile&quot;</span>&gt;</span>weightMapFile<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 用于测试时观察各物理节点与虚拟节点的分布情况，如果指定了这个属性，会把虚拟节点的 murmur hash 值与物理节 点的映射按行输出到这个文件，没有默认值，如果不指定，就不会输出任何东西 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;bucketMapPath&quot;</span>&gt;</span>/etc/mycat/bucketMapPath<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h1 id="11-按单月小时拆分"><a href="#11-按单月小时拆分" class="headerlink" title="11. 按单月小时拆分"></a>11. 按单月小时拆分</h1><p>此规则是单月内按照小时拆分，最小粒度是小时，可以一天最多 24 个分片，最少 1 个分片，一个月完后下月从头开始循环。每个月月尾，需要手工清理数据。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-hour&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>create_time<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-hour<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-hour&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.LatestMonthPartion&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;splitOneDay&quot;</span>&gt;</span>24<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段（字符串类型yyyyMMddHH）</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>splitOneDay</td>
<td>一天切分的分片数</td>
</tr>
</tbody></table>
<p><strong>注意</strong><br>分片字段必须为字符串格式，否则分片不成功，默认存到第一个分片里面；<br>保存的时间格式必须为‘yyyymmddHH’格式，不能多也不能少字符，否则分片不成功，默认存到第一个分片里面；</p>
<h1 id="12-范围求模分片"><a href="#12-范围求模分片" class="headerlink" title="12. 范围求模分片"></a>12. 范围求模分片</h1><p>先进行范围分片计算出分片组，组内再求模。<br>优点可以避免扩容时的数据迁移，又可以一定程度上避免范围分片的热点问题。<br>综合了范围分片和求模分片的优点，分片组内使用求模可以保证组内数据比较均匀，分片组之间是范围分片，可以兼顾范围查询。<br>最好事先规划好分片的数量，数据扩容时按分片组扩容，则原有分片组的数据不需要迁移。由于分片组内数据比较均匀，所以分片组内可以避免热点数据问题。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;auto-sharding-rang-mod&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>id<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>rang-mod<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;rang-mod&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByRangeMod&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;mapFile&quot;</span>&gt;</span>partition-range-mod.txt<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;defaultNode&quot;</span>&gt;</span>21<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>mapFile</td>
<td>配置文件路径</td>
</tr>
<tr>
<td>defaultNode</td>
<td>超过范围后的默认节点顺序号，节点从 0 开始。</td>
</tr>
</tbody></table>
<p>partition-range-mod.txt</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 以下配置一个范围代表一个分片组，&#x3D;号后面的数字代表该分片组所拥有的分片的数量。</span><br><span class="line"># range start-end ,data node group size</span><br><span class="line">0-200M&#x3D;5 &#x2F;&#x2F;代表有 5 个分片节点</span><br><span class="line">200M1-400M&#x3D;1</span><br><span class="line">400M1-600M&#x3D;4</span><br><span class="line">600M1-800M&#x3D;4</span><br><span class="line">800M1-1000M&#x3D;6</span><br></pre></td></tr></table></figure>

<p><strong>注意</strong><br>如上0-200M存入到5个分片中，开始范围-结束范围=该分片组有多少个分片。如果超过配置范围需要增加分片组。</p>
<h1 id="13-日期范围HASH分片"><a href="#13-日期范围HASH分片" class="headerlink" title="13. 日期范围HASH分片"></a>13. 日期范围HASH分片</h1><p>思想与范围求模一致，当由于日期在取模会有数据集中问题，所以改成 hash 方法。<br>先根据日期分组，再根据时间 hash 使得短期内数据分布的更均匀。<br>优点可以避免扩容时的数据迁移，又可以一定程度上避免范围分片的热点问题。要求日期格式尽量精确些，不然达不到局部均匀的目的</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;range-date-hash&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>col_date<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>range-date-hash<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;range-date-hash&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByRangeDateHash&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sBeginDate&quot;</span>&gt;</span>2014-01-01 00:00:00<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sPartionDay&quot;</span>&gt;</span>365<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;dateFormat&quot;</span>&gt;</span>yyyy-MM-dd HH:mm:ss<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;groupPartionSize&quot;</span>&gt;</span>3<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>sBeginDate</td>
<td>开始日期</td>
</tr>
<tr>
<td>sPartionDay</td>
<td>多少天一个分片</td>
</tr>
<tr>
<td>dateFormat</td>
<td>日期格式</td>
</tr>
<tr>
<td>groupPartionSize</td>
<td>分片组的大小</td>
</tr>
</tbody></table>
<p><strong>注意</strong><br>从sBeginDate时间开始计算，每sPartionDay天的数据为一个分片组，每个分片组可以分布在groupPartionSize个分片上面。上面的例子最多可以有三天进行分片，如果超出则会抛出以下异常。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can&#39;t find a valid data node for specified node index :ALAN_TEST -&gt; RANGE_DATE -&gt; 2019-01-11 12:00:00 -&gt; Index : 4</span><br><span class="line">The error may involve com.mycat.test.model.AlanTest.insert-Inline</span><br><span class="line">The error occurred while setting parameters</span><br></pre></td></tr></table></figure>

<h1 id="14-冷热数据分片"><a href="#14-冷热数据分片" class="headerlink" title="14. 冷热数据分片"></a>14. 冷热数据分片</h1><p>根据日期查询日志数据 冷热数据分布 ，最近 n 个月的到实时交易库查询，超过 n 个月的按照 m 天分片。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-date&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>create_time<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-hotdate<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-hotdate&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByHotDate&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;dateFormat&quot;</span>&gt;</span>yyyy-MM-dd<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sLastDay&quot;</span>&gt;</span>10<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sPartionDay&quot;</span>&gt;</span>30<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>dateFormat</td>
<td>日期格式</td>
</tr>
<tr>
<td>sLastDay</td>
<td>热数据的时间</td>
</tr>
<tr>
<td>sPartionDay</td>
<td>冷数据的分片天数（按照天数分片）</td>
</tr>
</tbody></table>
<p><strong>注意</strong><br>冷数据按照这个范围进行分片，例如上面的规则配置，今天是2019年1月21日，往前推10天为2019年1月12日，则2019年1月12日之前的数据为冷数据，该批冷数据的分片规则为30天一个分片，即2018-12-12至2019-01-11的数据放入第1个分片，2018-11-12至2018-12-11的数据放入第2个分片…以此类推，如果数据库分区不够，则在保存的时候会抛出以下异常</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can&#39;t find a valid data node for specified node index :ALAN_TEST -&gt; CREATE_DATE -&gt; 2018-11-09 12:00:00 -&gt; Index : 3</span><br></pre></td></tr></table></figure>

<h1 id="15-自然月分片"><a href="#15-自然月分片" class="headerlink" title="15. 自然月分片"></a>15. 自然月分片</h1><p>按月份列分区 ，每个自然月一个分片，格式 between 操作解析的范例。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">tableRule</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-month&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">rule</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">columns</span>&gt;</span>create_time<span class="tag">&lt;/<span class="name">columns</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">algorithm</span>&gt;</span>sharding-by-month<span class="tag">&lt;/<span class="name">algorithm</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">rule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">tableRule</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">function</span> <span class="attr">name</span>=<span class="string">&quot;sharding-by-month&quot;</span> <span class="attr">class</span>=<span class="string">&quot;io.mycat.route.function.PartitionByMonth&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;dateFormat&quot;</span>&gt;</span>yyyy-MM-dd<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;sBeginDate&quot;</span>&gt;</span>2014-01-01<span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">function</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>配置说明：</p>
<table>
<thead>
<tr>
<th>标签属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>columns</td>
<td>标识将要分片的表字段</td>
</tr>
<tr>
<td>algorithm</td>
<td>分片函数</td>
</tr>
<tr>
<td>dateFormat</td>
<td>日期格式</td>
</tr>
<tr>
<td>sBeginDate</td>
<td>开始日期（无默认值）</td>
</tr>
<tr>
<td>“sEndDate</td>
<td>结束日期（无默认值）</td>
</tr>
</tbody></table>
<p><strong>注意</strong></p>
<ol>
<li>默认设置，节点数量必须是12个，每12个月循环从开始分片插入</li>
<li>如配置了sBeginDate=”2019-01”月是第0个分片，从该时间按月递增，无最大节点</li>
<li>配置了sBeginDate = “2015-01-01”sEndDate = “2015-12-01”该配置可以看成和第一个一致</li>
<li>配置了sBeginDate = “2015-01-01”sEndDate = “2015-03-01”该配置标识只有 3 个节点；很难与月份对应上；平均分散到 3 个节点上</li>
</ol>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/mycat/" rel="tag"># mycat</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/09/17/%E9%80%9A%E4%BF%A1%E7%A7%91%E6%99%AE/" rel="prev" title="通信科普">
                  <i class="fa fa-chevron-left"></i> 通信科普
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/09/28/Spring-Cloud-Ribbon-%E7%9A%84%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E7%AD%96%E7%95%A5/" rel="next" title="Spring Cloud Ribbon 的负载均衡策略">
                  Spring Cloud Ribbon 的负载均衡策略 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/local-search.js"></script>






  





</body>
</html>
